﻿@{
    if (RequestHelper.QueryString("use") != "include")
    {
        ViewBag.Title = "所有文章";
        Layout = "~/Views/Shared/_Admin.cshtml";
    }
    IList<Post> posts = ViewData.Model as IList<Post> ?? new List<Post>();
    IList<Term> terms = ViewBag.Terms;
    IList<Term> formatCategorys = ViewBag.FormatCategorys;
    IList<Relation> relations = ViewBag.Relations;
}
<link type="text/css" href="/content/styles/posts.css?var=1.0" rel="stylesheet" />
<div class="hd-title">
    <h1 class="post">所有文章</h1>
</div>
<div id="message" class="alert">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <span></span>
</div>
<ul class="status">
    <li><a class="all" data-status="all" href="javascript:;">全部<span class="count"></span></a>&nbsp;|&nbsp;</li>
    <li><a class="publish current" data-status="0" href="javascript:;">已发布<span class="count"></span></a>&nbsp;|&nbsp;</li>
    <li><a class="trash" data-status="-1" href="javascript:;">草稿<span class="count"></span></a>&nbsp;|&nbsp;</li>
    <li><a class="trash" data-status="-3" href="javascript:;">回收站<span class="count"></span></a></li>
</ul>
<div class="input-append">
    <label for="txt_search" class="hide-text">搜索文章</label>
    <input id="txt_search" class="span2 search-post" type="text" placeholder="搜点什么？">
    <button class="btn btn-small" type="button">搜索</button>
</div>
<b class="clearfix"></b>
<div class="row-fluid">
    <select id="handle_top" class="sel-action">
        <option value="-1" selected="selected">批量操作</option>
        @*<option value="edit">编辑</option>
        <option value="normal">公开发表</option>*@
        <option value="trash">移至回收站</option>
    </select>
    <a class="do-action btn btn-mini" href="javascript:;">应用</a>
    @*<select id="sel_data">
        <option value="-1" selected="selected">批量操作</option>
        <option value="edit">编辑</option>
        <option value="trash">移至回收站</option>
    </select>*@
    <select id="sel_category">
        <option value="-1" selected="selected">所有目录下文章</option>
        @foreach (var category in formatCategorys)
        {
            <option value="@category.Id">@category.Name</option>
        }
    </select>
    <a class="do-select btn btn-mini" href="javascript:;">筛选</a>
</div>
<table class="table widefat table-hover table-striped">
    <thead>
        <tr>
            <th class="col-cb text-center">
                <label for="cb_all_top" class="hide-text">全选</label>
                <input id="cb_all_top" class="cb-all" type="checkbox" />
            </th>
            <th class="col-title">标题</th>
            @*<th class="col-author">作者</th>*@
            <th class="col-term">分类目录</th>
            <th class="col-term">标签</th>
            <th class="col-comment text-center"><i title="评论" class="icon-comment"></i></th>
            <th class="col-date">日期</th>
        </tr>
    </thead>
    <tbody id="post_list">
        @foreach (var item in posts)
        {
            var ids = relations.Where(r => r.ObjectId == item.Id).Select(r => r.TermId);
            var thisTerms = terms.Where(c => ids.Contains(c.Id));
            <tr id="post_@item.Id">
                <td class="text-center">
                    <label for="cb_post_@item.Id" class="hide-text">选择 @item.Title</label>
                    <input id="cb_post_@item.Id" class="cb-item" type="checkbox" /></td>
                <td>
                    <strong><a href="#@item.Id">@item.Title</a></strong>
                    <div class="row-actions">
                        <span class="open-edit"><a href="#editor?post=@item.Id" title="编辑此项目">编辑</a> | </span>
                        @*<span class="inline-edit"><a href="#" title="实时编辑此项目">快速编辑</a> | </span>*@
                        <span class="trash"><a title="移动此项目到回收站" href="#trash_@item.Id">移至回收站</a> | </span>
                        <span class="view"><a href="#@item.Id" title="查看“@item.Title”">查看</a></span>
                    </div>
                </td>
                @*<td>@item.UserId</td>*@
                <td>@Html.Raw(string.Join("、", thisTerms.Where(c => c.Type == (int)TermType.PostCategory).Select(c => string.Format("<a href=\"/category/{0}\" target=\"_blank\">{1}</a>", c.Slug, c.Name))))</td>
                <td>@Html.Raw(string.Join("、", thisTerms.Where(c => c.Type == (int)TermType.PostTag).Select(c => string.Format("<a href=\"/tag/{0}\" target=\"_blank\">{1}</a>", c.Slug, c.Name))))</td>
                <td class="text-center"><span class="badge">@item.CommentCount</span></td>
                <td>@StringHelper.DateTimeToChsStr(item.Modified)</td>
            </tr>
        }
        @if (posts.Count == 0)
        {
            <tr id="post_null">
                <td class="text-center">&nbsp;
                </td>
                <td>
                    <strong><a href="javascript:;">没有记录</a></strong>
                    <div class="row-actions">
                        &nbsp;
                    </div>
                </td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
        }
    </tbody>
    <tfoot>
        <tr>
            <th class="text-center">
                <label for="cb_all_bottom" class="hide-text">全选</label>
                <input id="cb_all_bottom" class="cb-all" type="checkbox" />
            </th>
            <th>标题</th>
            @*<th>作者</th>*@
            <th>分类目录</th>
            <th>标签</th>
            <th class="text-center"><i title="评论" class="icon-comment"></i></th>
            <th>日期</th>
        </tr>
    </tfoot>
</table>
<div class="row-fluid">
    <select id="handle_bottom" class="sel-action">
        <option value="-1" selected="selected">批量操作</option>
        <option value="trash">移至回收站</option>
    </select>
    <a id="do_action" class="do-action btn btn-mini" href="javascript:;">应用</a>
    @if (ViewBag.TotalPage > 0)
    {
        <div id="pager" data-total="@ViewBag.TotalPage"></div>
        <script type="text/javascript" src="/Content/scripts/bootstrap/paginator.js"></script>
        <script type='text/javascript'>
            var options = {
                currentPage: 1,
                totalPages: @ViewBag.TotalPage,
                numberOfPages: @(ViewBag.TotalPage > 5 ? 5 : ViewBag.TotalPage),
                size: 'small',
                useBootstrapTooltip: true,
                tooltipTitles: function(type, page, current) {
                    if (page == current) {
                        return '当前第' + page + '页';
                    }
                    switch (type) {
                    case 'first':
                        return '返回第一页';
                    case 'prev':
                        return '上一页';
                    case 'next':
                        return '下一页';
                    case 'last':
                        return '跳到最后一页';
                    case 'page':
                        return '跳到第' + page + '页';
                    }
                },
                onPageChanged: function(e, oldPage, newPage) {
                    setPage(newPage);
                }
            };
            $('#pager').bootstrapPaginator(options);
        </script>
    }
</div>
<script type="text/javascript" src="/content/scripts/posts.js"></script>
